<template>
  <div id="tab-bar-item" @click="tabBarItemClick">
    <div class="img" v-if="!isActive">
      <slot name="tab-bar-img"></slot>
    </div>
    <div class="img-active" v-else>
      <slot name="tab-bar-img-active"></slot>
    </div>
    <div :style="activeStyle">
      <slot name="tab-bar-text"></slot>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    path: {
      type: String,
    },
    activeColor: {
      type: String,
      default: "red",
    },
  },
  computed: {
    isActive() {
      return this.$route.path.indexOf(this.path) !== -1;
    },
    activeStyle() {
      return this.isActive ? { color: this.activeColor } : {};
    },
  },
  methods: {
    tabBarItemClick() {
      this.$router.replace(this.path);
    },
  },
};
</script>

<style>
#tab-bar-item {
  flex: 1;
  text-align: center;
}

img {
  height: 24px;
  vertical-align: middle;
}
</style>